<template>
  <div class="contact">
    <header class="page-header">
      <div class="container">
        <h1>联系我</h1>
        <p>期待与您交流</p>
      </div>
    </header>

    <main class="container">
      <div class="contact-content">
        <form @submit.prevent="handleSubmit" class="contact-form">
          <div class="form-group">
            <label for="name">
              <i class="icon fas fa-user"></i> 姓名
            </label>
            <input
              type="text"
              id="name"
              v-model="formData.name"
              required
              class="form-control"
              placeholder="请输入您的姓名"
            >
          </div>

          <div class="form-group">
            <label for="email">
              <i class="icon fas fa-envelope"></i> 邮箱
            </label>
            <input
              type="email"
              id="email"
              v-model="formData.email"
              required
              class="form-control"
              placeholder="请输入您的邮箱"
            >
          </div>

          <div class="form-group">
            <label for="message">
              <i class="icon fas fa-comment"></i> 留言内容
            </label>
            <textarea
              id="message"
              v-model="formData.message"
              required
              class="form-control"
              rows="6"
              placeholder="请输入您的留言内容"
            ></textarea>
          </div>

          <button type="submit" class="submit-button" :disabled="isSubmitting">
            <span v-if="!isSubmitting">
              <i class="fas fa-paper-plane"></i> 发送消息
            </span>
            <span v-else>
              <i class="fas fa-spinner fa-spin"></i> 发送中...
            </span>
          </button>
        </form>

        <div class="contact-info">
          <h2><i class="fas fa-address-card"></i> 其他联系方式</h2>
          <ul>
            <li>
              <i class="fas fa-envelope"></i>
              <strong>邮箱：</strong>
              <a href="mailto:zm_2002l@163.com">zm_2002l@163.com</a>
            </li>
            <li>
              <i class="fab fa-weixin"></i>
              <strong>微信：</strong>
              Z19120421759
            </li>
            <li>
              <i class="fas fa-map-marker-alt"></i>
              <strong>地址：</strong>
              江苏省南京市栖霞区
            </li>
          </ul>
        </div>
      </div>
    </main>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import emailjs from 'emailjs-com'

const formData = ref({
  name: '',
  email: '',
  message: ''
})

const isSubmitting = ref(false)

const handleSubmit = async () => {
  try {
    isSubmitting.value = true
    
    // 使用EmailJS直接发送邮件
    await emailjs.send(
      'service_t197wka', // 替换为你的EmailJS服务ID
      'template_5hh1btr', // 替换为你的EmailJS模板ID
      {
        from_name: formData.value.name,
        from_email: formData.value.email,
        message: formData.value.message,
        to_email: 'zm_2002l@163.com' // 你的接收邮箱
      },
      '2VcE91qat4PJjY51X' // 替换为你的EmailJS用户ID
    )
    
    alert('消息已发送成功！')
    // 清空表单
    formData.value = {
      name: '',
      email: '',
      message: ''
    }
  } catch (error) {
    console.error('提交失败：', error)
    alert(`发送失败：${error.message || '请稍后重试'}`)
  } finally {
    isSubmitting.value = false
  }
}
</script>

<style scoped>
/* 样式部分保持不变 */
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css');

.page-header {
  background: linear-gradient(135deg, rgba(173, 216, 230, 0.9), rgba(176, 224, 230, 0.9)), url('@/assets/img/contact-bg.jpg');
  background-blend-mode: overlay;
  color: #2c3e50;
  padding: 5rem 0;
  text-align: center;
  margin-bottom: 3rem;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  border-radius: 0 0 30px 30px;
  position: relative;
}

.page-header .container {
  position: relative;
  z-index: 1;
}

.page-header h1 {
  font-size: 3rem;
  margin-bottom: 1rem;
  color: #2c3e50;
  font-weight: 600;
}

.page-header p {
  font-size: 1.2rem;
  color: #4a6b8b;
}

.contact-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5rem;
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
  background-color: white;
  border-radius: 16px;
  box-shadow: 0 5px 25px rgba(0, 0, 0, 0.05);
}

.contact-form {
  margin-bottom: 0;
}

.form-group {
  margin-bottom: 5rem;
  position: relative;
}

label {
  display: block;
  margin-bottom: 0.8rem;
  color: #4a6b8b;
  font-weight: 600;
  font-size: 1rem;
}

.icon {
  margin-right: 8px;
  color: #6bb9f0;
}

.form-control {
  width: 100%;
  padding: 0.85rem 1rem 0.85rem 2.5rem;
  border: 1px solid #d1e0e7;
  border-radius: 10px;
  font-size: 1rem;
  transition: all 0.3s ease;
  background-color: #f8fbfd;
}

.form-control:focus {
  outline: none;
  border-color: #6bb9f0;
  box-shadow: 0 0 0 3px rgba(107, 185, 240, 0.2);
  background-color: white;
}

textarea.form-control {
  min-height: 180px;
  padding-left: 1rem;
}

.submit-button {
  background: linear-gradient(135deg, #6bb9f0, #4a89dc);
  color: white;
  padding: 0.9rem 2.5rem;
  border: none;
  border-radius: 10px;
  font-size: 1.05rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 10px rgba(107, 185, 240, 0.3);
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.submit-button:hover {
  background: linear-gradient(135deg, #4a89dc, #3b7dd8);
  transform: translateY(-2px);
  box-shadow: 0 6px 15px rgba(107, 185, 240, 0.4);
}

.submit-button:disabled {
  background: #bdc3c7;
  transform: none;
  box-shadow: none;
  cursor: not-allowed;
}

.contact-info {
  background-color: #f8fbfd;
  padding: 2.5rem;
  border-radius: 16px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.03);
  border: 1px solid #e1f0fa;
  align-self: start;
}

.contact-info h2 {
  color: #4a6b8b;
  margin-bottom: 1.8rem;
  font-size: 1.5rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

.contact-info ul {
  list-style: none;
  padding: 0;
}

.contact-info li {
  margin-bottom: 1.5rem;
  color: #4a6b8b;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 12px;
}

.contact-info i {
  width: 20px;
  color: #6bb9f0;
  font-size: 1.1rem;
}

.contact-info a {
  color: #4a89dc;
  text-decoration: none;
  transition: color 0.2s;
}

.contact-info a:hover {
  color: #3b7dd8;
  text-decoration: underline;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .contact-content {
    grid-template-columns: 1fr;
    padding: 1.5rem;
  }
  
  .page-header {
    padding: 3rem 0;
  }
  
  .page-header h1 {
    font-size: 2.2rem;
  }
}
</style>